package com.bigchun.woodhunter;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import myapp.MyApp;
import util.SystemStatusManager;

/**
 * @Author: ChenYao
 * @Describe: 协议
 * @Date: 2023/3/10 11:58
 */
public class ProtocolActivity extends BaseActivity {
    private LinearLayout ll_reback;
    private RelativeLayout rl_protocol_1;
    private RelativeLayout rl_protocol_2;
    private String apptype;
    private SharedPreferences sharedPreferences;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_protocol);
        initView();
        initData();
        setListener();
    }

    private void initView() {
        setTranslucentStatus();
        ll_reback = findViewById(R.id.ll_reback);
        rl_protocol_1 = findViewById(R.id.rl_protocol_1);
        rl_protocol_2 = findViewById(R.id.rl_protocol_2);
    }

    /**
     * 设置状态栏背景状态
     */
    public void setTranslucentStatus() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window win = getWindow();
            WindowManager.LayoutParams winParams = win.getAttributes();
            final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
            winParams.flags |= bits;
            win.setAttributes(winParams);
        }
        SystemStatusManager tintManager = new SystemStatusManager(this);
        tintManager.setStatusBarTintEnabled(true);
        tintManager.setStatusBarTintResource(0);//状态栏无背景
    }

    private void initData() {
        sharedPreferences = getSharedPreferences("userInfo", Context.MODE_PRIVATE);
        apptype = sharedPreferences.getString("apptype", "0");
    }

    private void setListener() {
        ll_reback.setOnClickListener(v -> {
            finish();
        });
        rl_protocol_1.setOnClickListener(v -> {
            Intent intent = new Intent(this, WebviewForXieyiActivity.class);
            if ("0".equals(apptype)) {
                intent.putExtra("url", MyApp.siteurl + "/template/mood.html");
            } else if ("1".equals(apptype)) {
                intent.putExtra("url", MyApp.siteurl + "/template/seeland.html");
            }
            startActivity(intent);
        });
        rl_protocol_2.setOnClickListener(v -> {
            Intent intent = new Intent(this, WebviewForXieyiActivity.class);
            if ("0".equals(apptype)) {
                intent.putExtra("url", MyApp.siteurl + "/api/formula/privacy");
            } else if ("1".equals(apptype)) {
                intent.putExtra("url", MyApp.siteurl + "/api/formula/see_privacy");
            }

            startActivity(intent);
        });
    }

}
